package com.grt192.controller.cannonbot;

import com.grt192.core.EventController;
import com.grt192.event.SensorEvent;
import com.grt192.event.component.ButtonListener;
import com.grt192.mechanism.GRTDriverStation;
import com.grt192.mechanism.cannonbot.CBCannon;
import com.grt192.sensor.GRTJoystick;

public class CBCannonController extends EventController implements
		ButtonListener {

	private GRTDriverStation ds;
	private CBCannon cannon;

	public CBCannonController(GRTDriverStation ds, CBCannon cannon) {
		super();
		this.ds = ds;
		((GRTJoystick) ds.getSensor("rightJoystick")).addButtonListener(this);
		((GRTJoystick) ds.getSensor("leftJoystick")).addButtonListener(this);
		this.cannon = cannon;
	}

	public void buttonDown(SensorEvent e, String key) {
	}

	public void buttonUp(SensorEvent e, String key) {
		if (key.equals("Button1")) {
			System.out.println("Firing auto");
			cannon.fire();
		} else if (key.equals("Button3")) {
			// Overrides
			if (e.getSource().getId().equals("leftJoystick")) {
				System.out.println("Firing LEFT manually");
				cannon.fireLeft();
			} else if (e.getSource().getId().equals("rightJoystick")) {
				System.out.println("Firing RIGHT manually");
				cannon.fireRight();
			}
		} else if (key.equals("Button5")) {
			// Overrides
			if (e.getSource().getId().equals("leftJoystick")) {
				System.out.println("Closing LEFT manually");
				cannon.closeLeft();
			} else if (e.getSource().getId().equals("rightJoystick")) {
				System.out.println("Closing RIGHT manually");
				cannon.closeRight();
			}
		} else if (key.equals("Button4")) {
			cannon.switchActiveBarrel();
		}
	}

}
